package com.wit.witmg.api;


import com.wit.witmg.service.ITProdmaterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author bob
 * @since 2024-12-23
 */
@RestController
@RequestMapping("prodmater")
@Api(tags = "产品配料API")
public class ProdmaterController {
    @Resource
    private ITProdmaterService service;

    @ApiOperation("添加")
    @PostMapping("add")
    public Object add(HttpServletRequest request,
                      @RequestParam("json") String json) {
        return service.add(request,json);
    }

    //参数：sid场地编号，返回sid以参数开头并包含参数的数据；oid部门编号，返回oid以参数开头并包含参数的数据；bn返回单条数据（前端支持二维码识别），id返回单条数据，常用于连表查询；
    @ApiOperation("获取")
    @PostMapping("get")
    public Object get(HttpServletRequest request,
                      @RequestParam(value = "size",required = false) String size,
                      @RequestParam(value = "bn",required = false) String bn) {
        return service.get(request,size,bn);
    }

    @ApiOperation("获取")
    @PostMapping("getqt")//参数：bn精确匹配一条BOM表数据，根据其mlist中的bn查询库存表，将库存数量添加到字段qt中返回，若不存在则qt为0。
    public Object getqt(HttpServletRequest request,
                      @RequestParam("bn") String bn,
                      @RequestParam("mqt") Double mqt,
                      @RequestParam("pid") Integer pid,
                      @RequestParam("eid") Long eid,
                      @RequestParam("ena") String ena,
                      @RequestParam(value = "oid",required = false,defaultValue = "0") Integer oid)

    {
        return service.getqt(request,bn,mqt,pid,eid,ena,oid);
    }

    @ApiOperation("删除")
    @PostMapping("del")
    public Object del(HttpServletRequest request,
                      @RequestParam("id") Integer id) {
        return service.del(request,id);
    }
}
